package com.usian.skill.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.skill.common.CodeMsg;
import com.usian.skill.common.Result;
import com.usian.skill.mapper.SkillOrderMapper;
import com.usian.skill.mapper.SkillUserMapper;
import com.usian.skill.pojo.SkillOrder;
import com.usian.skill.pojo.SkillUser;
import com.usian.skill.service.SkillOrderService;
import com.usian.skill.service.SkillUserService;
import com.usian.skill.util.AppJwtUtil;
import com.usian.skill.vo.LoginVo;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;
import org.thymeleaf.expression.Maps;

import javax.validation.constraints.NotNull;
import java.util.HashMap;

@Service
public class SkillUserServiceImpl extends ServiceImpl<SkillUserMapper, SkillUser> implements SkillUserService {
    @Override
    public Result login(LoginVo loginVo) {
        if(loginVo==null||loginVo.getMobile()==null){
            return Result.error(CodeMsg.MOBILE_EMPTY);
        }
         SkillUser skillUser = getById(loginVo.getMobile());
        if(skillUser.getPassword().equals(DigestUtils.md5Hex(loginVo.getPassword()+skillUser.getSalt()))){
            return Result.success(loginVo.getMobile());
        }else {
            return Result.error(CodeMsg.PASSWORD_ERROR);
        }
    }
}
